<?php
/**
 * Created by PhpStorm.
 * User: chinawolf
 * Date: 2018/3/3
 * Time: 9:33
 */
namespace app\command;
set_time_limit(0);


use app\index\controller\Api;
use think\Config;
use think\Controller;
use think\Db;
use think\Loader;
use think\Request;
class Test extends Controller
{
    /**
     * 获取数据操作对象
     * @return \think\db\Query
     */
    protected static function db()
    {
        return Db::name('test');
    }
    protected static function task_log_db()
    {
        return Db::name('timed_task_log');
    }

    public static  function firstTest(){
        $data = ['info' => 11];
        return self::db()->insert($data) !== false;
    }
    public static function add_timed_task_log($taskname=''){
        $data = ['taskname' => $taskname];
        return self::task_log_db()->insert($data) !== false;
    }

    /**
     * 一对一咨询，专家必须在30分钟内解答当事人的问题，否则系统将自动转为公开咨询
     * 使用：半小时执行一次
     * @author
     * @param string $type
     * @return \think\response\View
     */
    public static function getqihuo_data(){
        set_time_limit(0);
        //获取产品信息
        $api= new Api();
        $api->getdate();

    }



    /**
     * 每日早上处理昨天，没有处理的收益：每天最多向一个用户支付10次
     */
    public static  function op_olday_qianbao(){
        set_time_limit(0);
        $paylog_model =new Paylog();
        //首先用php获取当天的年份
        $y = date("Y");
        //首先用php获取当天的月份
        $m = date("m");
        //首先用php获取当天的号数（也就是几日，那今天来讲就是：11日）
        $d = date("d");
        $end_time = mktime(0,0,0,$m,$d,$y);
        $paylog_list =$paylog_model->where('p_type','in',[1,3,4,5,6,7,8])->where('user_type','in',[1,2])->where('is_fasong',0)->where('optime','<=',$end_time)
            ->field('uid,sum(order_money) as sum_money')->group('uid')->select()->toArray();
        if(is_array($paylog_list) && count($paylog_list)>0){
            foreach ($paylog_list as $key=>$val){
                if($val['sum_money'] >1){
                    $order_number =op_qianbao_pay($val['uid'], '昨天未结算完收益', $val['sum_money']);
                    if($order_number){
                        $pay_log_data =array();
                        $pay_log_data['is_fasong'] =1;
                        $pay_log_data['fasong_time'] =time();
                        $pay_log_data['is_process'] =1;
                        $paylog_model->where('p_type','in',[1,3,4,5,6,7,8])->where('user_type','in',[1,2])->where('optime','<=',$end_time)->update($pay_log_data);
                    }
                }
            }
        }
    }



}